package com.ibeeking.found.common.utils;

import com.ibeeking.found.common.entity.ScriptPublishParam;
import com.ibeeking.found.common.entity.TenantDataPushParam;
import com.ibeeking.found.common.enums.ApplicationEnum;
import com.ibeeking.found.common.enums.PushScriptDataEnum;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName DataPushUtils
 * @Description
 * @Author ibeeking
 * @Date 2021-05-06 18:13
 **/
public class DataPushUtils {

    public static TenantDataPushParam getSqlParam(List<Integer> tenantIds, List<String> sqls, ApplicationEnum application) {
        return getSqlParam(tenantIds, sqls, application, "数据脚本发布");
    }

    public static TenantDataPushParam getSqlParam(List<Integer> tenantIds, List<String> sqls, ApplicationEnum application, String description) {
        TenantDataPushParam param = new TenantDataPushParam();
        List<ScriptPublishParam> scripts = new ArrayList<>();
        sqls.stream().forEach(s -> {
            ScriptPublishParam scriptPublishParam = new ScriptPublishParam();
            scriptPublishParam.setApplication(application.name());
            scriptPublishParam.setSqlScript(s);
            scriptPublishParam.setDescription(description);
            scripts.add(scriptPublishParam);
        });
        param.setScripts(scripts);
        param.setTenantIds(tenantIds);
        param.setStatus(PushScriptDataEnum.UNEXECUTED.getCode());
        return param;
    }
}
